//
//  BaseEntity.m
//  ShenWeiRent
//
//  Created by 李叶夫 on 2019/3/12.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "BaseEntity.h"

@implementation BaseEntity

+ (instancetype)entity:(Class)class fromDictionary:(NSDictionary *)dictionary
{
    BaseEntity *baseEntity = [self yy_modelWithDictionary:dictionary];
    
    if ([dictionary[@"data"] isKindOfClass:[NSDictionary class]]) {
        NSDictionary *data = dictionary[@"data"];
        if (data) {
            id entity = [class yy_modelWithDictionary:data];
            baseEntity.data = entity;
        }
    }
    if ([dictionary[@"data"] isKindOfClass:[NSArray class]]) {
        NSArray *data = dictionary[@"data"];
        NSMutableArray *temp = @[].mutableCopy;
        for (int i = 0; i < data.count; i++) {
            if ([data[i] isKindOfClass:[NSDictionary class]]) {
                id entity = [class yy_modelWithDictionary:data[i]];
                [temp addObject:entity];
            }
        }
        baseEntity.data = temp.copy;
    }
    return baseEntity;
}

//+ (NSDictionary *)modelCustomPropertyMapper
//{
//    return @{
//             @"code":@"errno"
//             };
//}

@end
